package com.dan.codekit.view.recycler.official;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.dan.codekit.R;
import com.dan.codekit.view.recycler.base.BaseLoadFooter;


/**
 * 编写人: LongDa
 * 时间: 2017-11-2017/11/20 17:12
 * 功能描述:
 */

public class OfficialLoadFooter extends LinearLayout implements BaseLoadFooter {

    private View mFooter;
    private TextView mStateTv;
    private ProgressBar mProgressBar;

    public OfficialLoadFooter(Context context) {
        this(context, null);
    }

    public OfficialLoadFooter(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    private void initView(Context context) {
        setGravity(Gravity.CENTER);
        mFooter = LayoutInflater.from(context).inflate(R.layout.official_recycler_footer, this, true);
        mStateTv = mFooter.findViewById(R.id.tv_recycler_footer_state);
        mProgressBar = mFooter.findViewById(R.id.pullup_to_load_progress);

        setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
    }

    @Override
    public void setState(int state) {
        switch (state) {
            case STATE_NO_MORE:
                mProgressBar.setVisibility(GONE);
                mStateTv.setText(R.string.list_no_more);
                this.setVisibility(VISIBLE);
                break;
            case STATE_LOADING:
                mProgressBar.setVisibility(VISIBLE);
                mStateTv.setText(R.string.list_load_ing);
                this.setVisibility(VISIBLE);
                break;
            case STATE_LOAD_COMPLETE:
                mProgressBar.setVisibility(GONE);
                mStateTv.setText(R.string.list_load_complete);
                this.setVisibility(GONE);
                break;
        }
    }

    @Override
    public void setVisiable(int visiable) {
        setVisibility(visiable);
    }

    @Override
    public View getView() {
        return this;
    }


}
